<!-- 区域字典维护 -->
<template>
    <div style="height:100%;width:100%;position:relative;">
        <div class="pagetop">
            <div class="top-button">
                <el-button @click="btnAdd" icon="el-icon-plus" v-has="'PADD'" :disabled="bChangeFlag"
                    v-if="bShowBtn">新增</el-button>
                <el-button @click="btnDel" icon="el-icon-delete" v-has="'PDELETE'"
                    :disabled="detailData.parentregionid == '-1' ? true : bChangeFlag" v-if="bShowBtn">删除</el-button>
                <el-button @click="btnSave" icon="el-icon-document" v-has="'PMODIFY'" :disabled="!bChangeFlag"
                    v-if="bShowBtn">保存</el-button>
                <el-button @click="btnCancel" icon="el-icon-close" :disabled="!bChangeFlag" v-if="bShowBtn">取消</el-button>
                <el-button icon="el-icon-close" @click="btnExc">退出</el-button>
            </div>
        </div>
        <div class="pagecenter">
            <rm-layout-left :fixsize=300 :splitwidth=3 :minfixsize=200 :maxflxsize=600>
                <template v-slot:fix>
                    <div class="tree">
                        <el-tree :props="treeProps" :load="LoadNode" node-key="regionid" lazy
                            :default-current-keys="defaultExpandKeys" @node-click="NodeClick" :highlight-current="true"
                            ref="tree" :render-after-expand="true" empty-text="请先选择所属区域">
                        </el-tree>
                    </div>
                </template>
                <div style="width:100%;float:left;height:100%;border:1px solid #ccc;overflow:auto;">
                    <el-tabs style="height:100%;" type="border-card" @tab-click="handleClick" v-model="tabShowTitle">
                        <el-tab-pane label="区域信息" name="tabname_qyxx">
                            <div class="right-  -smrk-1">
                                <table class="edit" style="padding:5px;border-collapse:separate; border-spacing:3px 4px;">
                                    <tr>
                                        <td>区域ID</td>
                                        <td>
                                            <el-input style="width:100%;" v-model="detailData.regionid"
                                                :disabled="true"></el-input>
                                        </td>
                                        <td>上级区域</td>
                                        <td>
                                            <el-input style="width:100%;" v-model="detailData.parentna"
                                                :disabled="true"></el-input>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>区域层次</td>
                                        <td>
                                            <el-input style="width:100%;" v-model="detailData.regionlevel"
                                                :disabled="true"></el-input>
                                        </td>
                                        <td>存在子类</td>
                                        <td>
                                            <el-checkbox style="width:100%;" v-model="detailData.havechild" true-label="1"
                                                false-label="0" disabled></el-checkbox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>区域代码</td>
                                        <td colspan=1>
                                            <el-input v-model="detailData.regioncode" ref="input0" maxlength="3"
                                                minlength="3" :disabled="true"></el-input>
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td style="color:#F56C6C">区域名称</td>
                                        <td colspan=3>
                                            <el-input v-model="detailData.regionname" ref="input1"
                                                @keyup.enter.native="NextFocus(1)" @input="GetInputCode"
                                                @focus="Focus($event)"></el-input>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>助记符</td>
                                        <td>
                                            <el-input style="width:100%;" v-model="detailData.inputcode" ref="input2"
                                                @keyup.enter.native="NextFocus(2)" @focus="Focus($event)"
                                                @input="HasChange"></el-input>
                                        </td>
                                        <td>默认销售</td>
                                        <td>
                                            <rm-ddl-common datatype="employee" dataname="销售用户" v-model="detailData.salesno"
                                                ref="input3" width="100%" @keyup.enter.native="NextFocus(3)"
                                                @change="SalesNoChange"></rm-ddl-common>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="vertical-align:top">备注</td>
                                        <td colspan=3>
                                            <el-input type="textarea" :rows="3" v-model="detailData.comments" ref="input4"
                                                @keyup.enter.native="NextFocus(4)" @focus="Focus($event)"
                                                @input="HasChange"></el-input>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="医院列表" name="tabname_yylb">
                            <div style="font-size: 12px; color: blue;height: 20px">双击左边添加，双击右边删除
                                <!-- <table>
                                    <tr>
                                        <td>快速查询</td>
                                        <td style="width: 400px">
                                            <el-input size="small" style="width: 150px" v-model="tab_nohoslist_seachstr" @keyup.enter.native="tab_get_search" placeholder="输入医院名称|医院代码"></el-input>
                                        </td>
                                        <td style="font-size: 12px; color: blue;">双击左边添加，双击右边删除</td>
                                        <td style="width: 100px">&nbsp;</td>
                                        <td>快速查询</td>
                                        <td style="width: 400px">
                                            <el-input size="small" style="width: 150px" v-model="tab_havehoslist_seachstr" @keyup.enter.native="tab_get_search" placeholder="输入医院名称|医院代码"></el-input>
                                        </td>
                                    </tr>
                                </table> -->
                            </div>

                            <div class="middle-tab-bottom">

                                <div style="float: left; width: 100%; height: 26px">
                                    <div
                                        style="float: left; width: calc(50% - 23px); height: 100%; text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">
                                        未对照医院</div>
                                    <div style="float: left; width: 40px; height: 100%; text-align:"></div>
                                    <div
                                        style="float: left; height: 100%; width: calc(50% - 23px); text-align: center; background: #f5f5f5; border: solid 1px #ccc; line-height: 26px; font-size: 13px">
                                        已对照医院</div>
                                </div>
                                <div style="float: left; width: 100%; height: 26px;">
                                    <div
                                        style="float: left; width: calc(50% - 23px); height: 100%;  border: solid 1px #ccc; ">
                                        快速查询:<el-input size="small" style="width: 150px" v-model="tab_nohoslist_seachstr"
                                            @keyup.enter.native="tab_get_search" placeholder="输入医院名称|医院代码"></el-input>
                                    </div>
                                    <div style="float: left; width: 40px; height: 100%; text-align:"></div>
                                    <div
                                        style="float: left; width: calc(50% - 23px); height: 100%; border: solid 1px #ccc;  ">
                                        快速查询:<el-input size="small" style="width: 150px" v-model="tab_havehoslist_seachstr"
                                            @keyup.enter.native="tab_get_search" placeholder="输入医院名称|医院代码"></el-input>
                                    </div>
                                </div>


                                <div style="float: left; width: 100%; height: calc(100% - 56px); margin-top: -1px">
                                    <div style="float: left; width: calc(50% - 23px); height: 100%">
                                        <vxe-table :data.sync="noegionhosp_TableData" border fit height="auto" whith="300"
                                            header-align="center" highlight-current-row highlight-hover-row
                                            ref="nohosp_Table" resizable show-header-overflow="tooltip"
                                            show-overflow="tooltip" size="mini" stripe :key="yylbkey"
                                            @cell-dblclick="tab_yylb_noregion_dbclickEvent">
                                            <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                                            <vxe-table-column field="hospitalname" title="未对照医院名称" align="center"
                                                width="160"></vxe-table-column>
                                            <vxe-table-column field="regionlevel" title="层次" align="center"
                                                width="35"></vxe-table-column>
                                            <vxe-table-column field="regionname" title="所属区域" align="left"
                                                header-align="center" width="180"></vxe-table-column>
                                            <vxe-table-column field="hospcode" title="医院代码" align="center"
                                                width="150"></vxe-table-column>
                                        </vxe-table>
                                    </div>
                                    <div class="table-deal-btn" style="float: left; width: 20px; height: 100%;">
                                        <div class="table-deal-btn-item">
                                            <div>
                                                <el-button class="el-icon-d-arrow-right"
                                                    @click="SetMultipleSelect"></el-button>
                                            </div>
                                            <div>
                                                <el-button class="el-icon-d-arrow-left"
                                                    @click="DelMultipleSelect"></el-button>
                                            </div>
                                        </div>
                                    </div>
                                    <div style="float: left; height: 100%; width: calc(50% - 23px);">
                                        <vxe-table :data.sync="hosp_TableData" border fit height="auto" whith="600"
                                            header-align="center" highlight-current-row highlight-hover-row ref="hosp_Table"
                                            resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini"
                                            stripe :key="yylbkey" @cell-dblclick="tab_yylb_havenregion_dbclickEvent">
                                            <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                                            <vxe-table-column field="hospitalname" title="已对照医院名称" align="center"
                                                width="160"></vxe-table-column>
                                            <vxe-table-column field="regionlevel" title="层次" align="center"
                                                width="35"></vxe-table-column>
                                            <vxe-table-column field="regionname" title="所属区域" align="left"
                                                header-align="center" width="180"></vxe-table-column>
                                            <vxe-table-column field="hospcode" title="医院代码" align="center"
                                                width="150"></vxe-table-column>
                                        </vxe-table>
                                    </div>
                                </div>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="采购中心" name="tabname_cgzx">
                            <div style="height: 100%;">
                                <vxe-table :data.sync="inv_org_TableData" border fit height="auto" header-align="center"
                                    highlight-current-row highlight-hover-row ref="inv_org__Table" resizable
                                    show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe
                                    :key="cgzxkey">
                                    <vxe-table-column field="orgname" title="机构名称" align="left" header-align="center"
                                        width="140"></vxe-table-column>
                                    <vxe-table-column field="regionlevel" title="层次" align="center"
                                        width="35"></vxe-table-column>\
                                    <vxe-table-column field="regionname" title="所属区域" align="left" header-align="center"
                                        width="200"></vxe-table-column>

                                    <vxe-table-column field="orgna" title="机构简称" align="left" header-align="center"
                                        width="90"></vxe-table-column>

                                    <vxe-table-column field="invorgid" title="机构ID" align="center"
                                        width="60"></vxe-table-column>
                                    <vxe-table-column field="invorgcode" title="机构代码" align="center"
                                        width="70"></vxe-table-column>
                                </vxe-table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div>
                <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="提示"
                    :visible.sync="bDelVisable" width="500px" height="300px">
                    <span class="el-icon-warning">确定删除<b> 区域:</b><b style="color:#F56C6C">{{ delNa }} </b>的记录吗？</span>
                    <span slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="btnDelComfirm">确 定</el-button>
                        <el-button @click="btnCancel(1)" :autofocus="true">取 消</el-button>
                    </span>
                </el-dialog>
            </rm-layout-left>
        </div>
    </div>
</template>

<script >
import { Promise } from "q";
import XEUtils from "xe-utils";
export default {
    name: "MNG114",
    data() {
        return {
            bShowBtn: true,
            bLoading: false,
            bDelVisable: false,
            bCopyVisable: false,
            bChangeFlag: false,
            bHospitalBtn: false,
            bPageInitLoading: false,
            yylbkey: 0, //初始化空数据表格高度
            cgzxkey: 0,
            regionid: -1, //节点
            fatherlocid: -1, //父节点
            delNa: "", //删除的区域名
            dontdel: "2",
            actionindex: "M",
            tabShowTitle: "tabname_qyxx",
            tpNode: {},
            prTpNode: {},
            childNode: {},
            detailData: {
                regionid: null,
                parentregionid: null,
                regionlevel: null,
                havechild: "",
                regioncode: "",
                regionname: "",
                inputcode: "",
                salesno: "",
                description: "",
            },
            treeProps: {
                label: "name",
                children: "children",
                isLeaf: "leaf",
            },
            popData: {
                //表达式弹窗数据
                librid: 0,
                validtypeno: "",
                validtypename: "",
                validformula: "",
                description: "",
            },
            tmpdetailData: {},
            hosp_TableData: [],
            noegionhosp_TableData: [],
            inv_org_TableData: [],
            defaultExpandKeys: [0],

            selectflag: 0,

            popcommonVisible: false,
            multiplepopcommon: true,
            popdatatype: "",

            tab_havehoslist_seachstr: "",
            tab_nohoslist_seachstr: "",
        };
    },
    created() {
        this.defaultExpandKeys = [2];
    },
    updated() { },
    methods: {
        handleClick(tab, evt) {
            if (tab.name == "tabname_qyxx") {
                this.bShowBtn = true;
                this.bHospitalBtn = false;
            } else if (tab.name == "tabname_yylb") {
                this.bShowBtn = false;
                this.bHospitalBtn = true;
            } else {
                this.bShowBtn = false;
                this.bHospitalBtn = false;
            }
            this.yylbkey++;
            this.cgzxkey++;
        },
        // ------------------------------左侧树--------------------------//
        //点击事件
        NodeClick(data, node, key) {
            if (this.bChangeFlag) {
                this.$refs.tree.setCurrentKey(this.tpNode.data.regionid);
                return false;
            } else {
                this.detailData = {};
                this.hosp_TableData = [];
                this.noegionhosp_TableData = [];
                this.inv_org_TableData = [];
                this.tab_havehoslist_seachstr = "";
                this.tab_nohoslist_seachstr = "";
                this.tpNode = node; //节点
                this.prTpNode = node.parent; //父节点
                this.regionid = this.$refs.tree.getCurrentNode(node.children).regionid;
                this.actionindex = "M";
                this.detailQuery(this.regionid);
            }
        },
        getCurrentData() {
            //用于更新删除、新增的数据   getCurrentNode 获取的是data getNode(key or data) 获取结点
            this.detailData = {};
            this.hosp_TableData = [];
            this.noegionhosp_TableData = [];
            this.inv_org_TableData = [];
            this.tpNode = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode());
            this.prTpNode = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode()).parent;
            this.regionid = this.$refs.tree.getCurrentNode().regionid;
        },
        //懒加载
        async LoadNode(node, resolve) {
            //展开第一级节点，从后台加载一级节点列表
            if (node.level == 0) {
                this.node_had = node;
                this.resolve_had = resolve;
                var data = await this.GetFatherTree(this.regionid);
                return resolve(data);
            } else if (node.level >= 1) {
                //展开其他子节点，动态从后台加载下一级节点列表
                var data = await this.GetChildTree(node.data.regionid, node);
                if (data.length == 0) {
                    node.leaf = true;
                    node.icon = "el-icon-document-copy";
                }
                return resolve(data);
            }
        },
        btnQuery() {
            //选择对应样本库的树 缺少记录当前展开的方法 暂不使用
            this.regionid = -1;
            this.node_had.childNodes = []; //把存起来的node的子节点清空，避免出现重复树.
            this.LoadNode(this.node_had, this.resolve_had); //再次执行懒加载的方法,载入新的树节点
        },
        btnRefreshLoc(node) {
            //重新加载子节点
            node.loaded = false;
            node.expand(); // 主动调用展开节点方法，重新查询该节点下的所有子节点
        },
        async GetFatherTree() {
            //父节点:加载第一级节点
            try {
                let tempNode = [];
                const res = await this.$tool.request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_query",
                        regionid: this.regionid,
                    },
                });
                if (res.RData.Data) {
                    res.RData.Data.forEach((item) => {
                        let node = {};
                        node.name = item.regionname;
                        node.regionid = item.regionid;
                        node.icon = "el-icon-house";
                        tempNode.push(node);
                        this.fatherlocid = item.regionid;
                    });
                }
                setTimeout(() => {
                    this.$refs.tree.setCurrentKey(res.RData.Data[0].regionid);
                    this.getCurrentData();
                    this.$refs.tree.store.nodesMap[res.RData.Data[0].regionid].expanded = false;
                    setTimeout(() => {
                        this.detailQuery(res.RData.Data[0].regionid);
                    }, 15);
                }, 80);
                return tempNode;
            } catch (e) {
                this.$message.warning(e.message);
            }
        },
        async GetChildTree(regionid, Node) {
            //子节点:每次加载下一级子节点
            try {
                let tempNode = [];
                const res = await this.$tool.request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_query_child",
                        regionid: regionid,
                    },
                });
                if (res.Data) {
                    res.Data.forEach((item) => {
                        let node = {};
                        node.name = item.regionname;
                        node.regionid = item.regionid;
                        node.leaf = false;
                        // node.icon = "el-icon-place"
                        tempNode.push(node);
                    });
                }
                return tempNode;
            } catch (e) {
                this.$message.warning(e.message);
            }
        },
        RenderContent(h, { node, data, store }) {
            //节点图标
            return (
                <span>
                    <i class={data.icon}></i>
                    <span> {node.label}</span>
                </span>
            );
        },
        /*-----------------------------按钮类-----------------------------*/
        /*左侧树 右键菜单 */
        btnAdd() {
            if (this.$refs.tree.getCurrentNode() == null) {
                //未选择节点，取消操作
                this.$message.info("请先选择一条区域数据。");
            } else {
                this.bChangeFlag = true;
                this.detailData = {
                    regioncode: "",
                    parentregionid: this.regionid,
                    parentna: this.tmpdetailData.regionname + "(" + this.tmpdetailData.regioncode + ")",
                    regionlevel: XEUtils.toNumber(this.tmpdetailData.regionlevel) + 1,
                    havechild: 0,
                    comments: "",
                    salesno: "",
                };
                this.hosp_TableData = [];
                this.noegionhosp_TableData = [];
                this.inv_org_TableData = [];
                setTimeout(() => {
                    this.$refs.input1.focus();
                }, 15);
            }
        },
        btnDel() {
            if (this.dontdel == "2") {
                this.$message({ type: "error", message: "获取数据失败，禁止删除！" });
                return false;
            } else if (this.dontdel == "1") {
                this.$message({ type: "error", message: "当前区域下存在采购中心或医院,禁止删除!" });
                return false;
            } else {
                var node = this.$refs.tree.getCurrentNode();
                this.delNa = node.name;
                this.bDelVisable = true;
            }
        },
        btnDelComfirm() {
            this.bDelVisable = false;
            let that = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_delete",
                        regionid: this.regionid,
                    },
                })
                .then((res) => {
                    if (res.errorcode == "1") {
                        this.$message({
                            message: "删除成功！",
                            type: "success",
                        });
                        this.actionindex = "M";
                        this.detailData = {};
                        this.hosp_TableData = [];
                        this.noegionhosp_TableData = [];
                        this.inv_org_TableData = [];
                        this.delNa = "";
                        this.btnRefreshLoc(this.prTpNode);
                        this.$refs.tree.setCurrentKey(res.keyid);
                        this.getCurrentData();
                        this.detailQuery(res.keyid);
                        //是删除操作
                    } else {
                        this.$message.error("删除失败！" + res);
                    }
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        async detailQuery(regionid) {
            try {
                this.dontdel = "2"; //0 无医院及采购中心  1有 ，用于禁止删除 2查询失败
                this.bPageInitLoading = true;
                const res = await this.$tool.request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_query_addoredit",
                        regionid: regionid,
                        havehoslist_seachstr: this.tab_havehoslist_seachstr,
                        nohoslist_seachstr: this.tab_nohoslist_seachstr,
                    },
                });
                if (res.noregionhosData.length > 0) {
                    this.noegionhosp_TableData = res.noregionhosData;
                } else {
                    this.noegionhosp_TableData = [];
                }

                if (res.regionlist.length > 0) {
                    this.detailData = res.regionlist[0];
                } else {
                    this.detailData = {};
                }
                this.tmpdetailData = XEUtils.clone(this.detailData, true);
                if (res.hosData.length > 0) {
                    this.hosp_TableData = res.hosData;
                    this.$refs.hosp_Table.setCurrentRow(res.hosData[0]);
                    this.tmpdetailData = XEUtils.clone(this.detailData, true);
                } else {
                    this.hosp_TableData = [];
                }
                if (res.inv_orgData) {
                    if (res.inv_orgData.length > 0) {
                        this.inv_org_TableData = res.inv_orgData;
                        this.tmpdetailData = XEUtils.clone(this.detailData, true);
                        this.$refs.inv_org__Table.setCurrentRow(res.inv_orgData[0]);
                    } else {
                        this.inv_org_TableData = [];
                    }
                }
                this.dontdel = res.dontdel;
                this.bPageInitLoading = false;
            } catch (e) {
                this.bPageInitLoading = false;
            }
        },
        //保存
        async btnSave() {
            if (!this.detailData.regionname) {
                this.$alert("区域名称不能为空！");
                this.$refs.input1.focus();
                return false;
            }
            try {
                const res = await this.$tool.request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_addedit",
                        parentregioncode: this.tmpdetailData.regioncode,
                        data: this.detailData,
                        havechild: this.tmpdetailData.regionlevel == "1" ? "1" : "0",
                    },
                });
                if (res.errcode == "1") {
                    this.$message({
                        message: "保存成功！",
                        type: "success",
                    });
                    if (res.actionindex == "A") {
                        //新增刷新父节点
                        this.btnRefreshLoc(this.tpNode);
                    } else if (res.actionindex == "M") {
                        //修改刷新当前节点
                        this.btnRefreshLoc(this.prTpNode);
                    }
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(res.keyid);
                        this.getCurrentData();
                        setTimeout(() => {
                            this.detailQuery(res.keyid);
                        }, 15);
                    }, 80);
                    this.bChangeFlag = false;
                } else {
                    this.$message({ message: res.obj, type: "error" });
                }
            } catch (e) {
                console.log(e);
                this.$message({ message: e, type: "error" });
            }
        },
        btnCancel() {
            this.$confirm("您确定要取消这次改动吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.bChangeFlag = false;
                    this.bDelVisable = false;
                    this.detailQuery(this.regionid);
                })
                .catch((e) => {
                    this.$$message.error(e);
                });
        },
        btnExc() {
            let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "MNG114");
            this.$parent.$refs.itemtags.tagsList.splice(index, 1);
            this.$router.go(-1);
        },
        // 焦点跳转
        NextFocus(index) {
            var focusIndex = index + 1;
            var that = this;
            if (index < 4) {
                setTimeout(function () {
                    if (index == 3) that.$refs["input" + index].$refs.ddlmainSelect.blur();
                    if (index != 2) that.$refs["input" + focusIndex].focus();
                    else that.$refs["input" + focusIndex].$refs.ddlmainSelect.focus();
                }, 5);
            }
        },
        GetInputCode() {
            this.bChangeFlag = true;
            this.detailData.inputcode = this.$pub.CreateInputcode(this.detailData.regionname, this, 16);
        },
        SalesNoChange(c, v) {
            this.bChangeFlag = true;
            this.detailData.salesno = c;
            this.$refs.input3.$refs.ddlmainSelect.blur();
        },
        Focus(event) {
            //点击触发文本内容全选
            event.currentTarget.select();
        },
        HasChange() {
            this.bChangeFlag = true;
        },
        openMultiplepop(popdatatype) {
            this.popdatatype = popdatatype;
            this.popcommonVisible = true;
        },
        tab_yylb_noregion_dbclickEvent({ row, rowIndex, column, columnIndex }, event) {
            var regionid = this.regionid;

            this.$tool
                .request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_update_hospitalregion",
                        regionid: regionid,
                        hospitalcode: row.hospcode,
                    },
                })
                .then((res) => {
                    if (res.errcode == 1) {
                        this.$message({
                            message: "保存成功",
                            type: "success",
                        });

                        this.detailQuery(regionid);

                    } else {
                        this.$confirm("保存失败:" + res.errmsg, "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            focusCancelButton: false,
                            type: "warning",
                        });
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        tab_yylb_havenregion_dbclickEvent({ row, rowIndex, column, columnIndex }, event) {
            var regionid = this.regionid;

            let _this = this;
            this.$tool
                .request({
                    url: "MNG/MNG1/MNG114",
                    method: "post",
                    data: {
                        action: "dc_region_del_hospitalregion",
                        hospitalcode: row.hospcode,
                    },
                })
                .then((res) => {
                    if (res.errcode == 1) {
                        this.$message({
                            message: "删除成功",
                            type: "success",
                        });

                        this.detailQuery(regionid);

                    } else {
                        this.$confirm("删除失败:" + res.errmsg, "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            focusCancelButton: false,
                            type: "warning",
                        });
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },
        //多选 右移
        SetMultipleSelect() {
            var regionid = this.regionid;
            var rows = this.$refs.nohosp_Table.getSelectRecords();
            var hospcodes = "";
            if (rows.length > 0) {
                for (let index = 0; index < rows.length; index++) {
                    hospcodes += rows[index].hospcode + ",";
                }
                hospcodes = hospcodes.substring(0, hospcodes.length - 1);

                this.$tool
                    .request({
                        url: "MNG/MNG1/MNG114",
                        method: "post",
                        data: {
                            action: "dc_region_update_hospitalregion",
                            regionid: regionid,
                            hospitalcode: hospcodes,
                        },
                    })
                    .then((res) => {
                        if (res.errcode == 1) {
                            this.$message({
                                message: "保存成功",
                                type: "success",
                            });

                            this.detailQuery(regionid);

                        } else {
                            this.$confirm("保存失败:" + res.errmsg, "提示", {
                                confirmButtonText: "确定",
                                cancelButtonText: "取消",
                                focusCancelButton: false,
                                type: "warning",
                            });
                        }
                    })
                    .catch((error) => {
                        console.log(error);
                    });
            }
            else {
                this.$message({
                    message: "请先选择数据",
                    type: "warning",
                });
            }
        },
        //多选 左移
        DelMultipleSelect() {
            var regionid = this.regionid;
            var rows = this.$refs.hosp_Table.getSelectRecords();
            var hospcodes = "";
            if (rows.length > 0) {
                for (let index = 0; index < rows.length; index++) {
                    hospcodes += rows[index].hospcode + ",";
                }
                hospcodes = hospcodes.substring(0, hospcodes.length - 1);

                this.$tool
                    .request({
                        url: "MNG/MNG1/MNG114",
                        method: "post",
                        data: {
                            action: "dc_region_del_hospitalregion",
                            hospitalcode: hospcodes,
                        },
                    })
                    .then((res) => {
                        if (res.errcode == 1) {
                            this.$message({
                                message: "删除成功",
                                type: "success",
                            });

                            this.detailQuery(regionid);

                        } else {
                            this.$confirm("删除失败:" + res.errmsg, "提示", {
                                confirmButtonText: "确定",
                                cancelButtonText: "取消",
                                focusCancelButton: false,
                                type: "warning",
                            });
                        }
                    })
                    .catch((error) => {
                        console.log(error);
                    });
            }
            else {
                this.$message({
                    message: "请先选择数据",
                    type: "warning",
                });
            }
        },
        //快速查询
        tab_get_search() {
            var regionid = this.regionid;
            this.detailQuery(regionid);
        },
        //区域代码改为后台生成,暂时注释
        // ChkRegioncode(){
        //     this.detailData.regioncode = this.detailData.regioncode.replace(/[^\d]/g, '')
        //     this.bChangeFlag = true;
        // },
        // AddPreZero(){//自动补零
        //     var fullregioncode = '000'+this.detailData.regioncode
        //     this.detailData.regioncode = fullregioncode.slice(-3);
        // }
    },
};
</script>
<style scoped>
.pagetop {
    width: 100%;
    height: 35px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    font-size: 12px;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}

.pagetop .top-table {
    float: right;
}

.top-button {
    right: 5px;
    position: absolute;
    top: 5px;
    display: flex;
    align-items: center;
}

.pagecenter {
    position: absolute;
    top: 40px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.RightBack {
    background-color: white;
}

.el-tree {
    min-width: 100%;
    font-size: 14px;
    display: inline-block;
}

.tree {
    overflow-y: auto;
    overflow-x: scroll;
    height: 100%;
    border: 1px solid #ccc;
}

::v-deep .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
    background-color: #b6e8ff;
    font-weight: 700;
}

table.edit tr td:nth-child(odd) {
    text-align: right;
    font-size: 12px;
    white-space: nowrap;
}

table.edit tr td:nth-child(even) {
    text-align: left;
}

::v-deep .el-button.is-disabled {
    border: 0px;
    color: grey;
    background-color: #e6e6e6;
    font-weight: normal;
}

::v-deep .innerRight.el-input.el-input__inner {
    text-align: right !important;
}

::v-deep .el-textarea__inner {
    padding: 3px 5px;
}

::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
}

::v-deep .vxe-table .vxe-body--column.col-orange {
    background-color: #f8f8f8;
}

::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #000000;
}

::v-deep tr.vxe-body--row.row--current {
    color: #000000;
    font-weight: bold;
}

.table-deal-btn {
    text-align: center;
    margin-left: 10px;
    margin-right: 10px;
    margin-top: auto;
    margin-bottom: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.table-deal-btn-item div {
    margin: 5px 0;
}

.middle-tab-bottom {
    position: absolute;
    top: 20px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
</style>